/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.classdiagram.helper;

import java.util.ArrayList;

import org.eclipse.draw2d.geometry.Dimension;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.uml2.uml.Behavior;
import org.eclipse.uml2.uml.BehavioralFeature;
import org.eclipse.uml2.uml.Element;
import org.eclipse.uml2.uml.Parameter;

import com.cea.papyrus.core.helper.NodeHelper;
import com.cea.papyrus.core.utils.Debug;
import com.cea.papyrus.diagraminterchange2.di2.Diagram;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;
import com.cea.papyrus.diagraminterchange2.di2.GraphNode;

/**
 * Factory that can create and delete a {@link Parameter}}.
 * 
 * @author Patrick Tessier, Remi Schnekenburger
 */
public class NodeParameterHelper extends NodeHelper {

	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.factories.NodeFactory#createGraphElement(org.eclipse.uml2.uml.Element, com.cea.papyrus.diagraminterchange2.di2.GraphElement, org.eclipse.draw2d.geometry.Point, org.eclipse.draw2d.geometry.Dimension)
	 */
	@Override
	public GraphNode createGraphElement(Element umlChild, GraphElement parent, Point location, Dimension size) {
		Debug.debug(this, "Call NodeParameterFactory.createGraphElement()", channel); //$NON-NLS-1$
		return null;
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.factories.INodeFactory#createGraphNode(org.eclipse.uml2.uml.NamedElement, com.cea.papyrus.diagraminterchange2.di2.Diagram)
	 */
	@Override
	public ArrayList createGraphNode(Element umlElement, Diagram diagram) {
		return new ArrayList();
	}

	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.factories.NodeFactory#canCreateGraphElement(com.cea.papyrus.diagraminterchange2.di2.GraphNode)
	 */
	@Override
	public boolean canCreateGraphElement(GraphElement parent){
		return true;
	}
	
	///////////////////////////////////////////////////////////////////////////
	// UML Management
	///////////////////////////////////////////////////////////////////////////
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.factories.NodeFactory#createElement(java.lang.String, org.eclipse.uml2.uml.Element)
	 */
	@Override
	public  org.eclipse.uml2.uml.Parameter createUMLElement(String name,  org.eclipse.uml2.uml.Element umlParent){
		Debug.debug(this,"Call NodeParameterFactory.createElement()", channel); //$NON-NLS-1$
		Parameter aparam = null;
		if (umlParent instanceof BehavioralFeature) {
			aparam=((BehavioralFeature)umlParent).createOwnedParameter(name,null);
		} else if (umlParent instanceof Behavior) {
			aparam=((Behavior)umlParent).createOwnedParameter(name,null);
		}
		return aparam;
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.factories.NodeFactory#canExecuteCreateElement(org.eclipse.uml2.uml.Element)
	 */
	@Override
	public boolean canCreateUMLElement(Element umlParent) {
		if (umlParent instanceof BehavioralFeature) {
			return true;
		}
		if (umlParent instanceof Behavior) {
			return true;
		}
		return false;
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.factories.NodeFactory#addElement(org.eclipse.uml2.uml.Element, org.eclipse.uml2.uml.Element)
	 */
	@Override
	public boolean addUMLElement(Element element, Element umlParent) {
		if (umlParent instanceof BehavioralFeature) {
			return ((BehavioralFeature)umlParent).getOwnedParameters().add((Parameter)element);
		}
		if(umlParent instanceof Behavior) {
			return ((Behavior)umlParent).getOwnedParameters().add((Parameter)element);
		}
		return false;
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.factories.NodeFactory#removeElement(org.eclipse.uml2.uml.Element, org.eclipse.uml2.uml.Element)
	 */
	@Override
	public boolean removeUMLElement(Element element, Element umlParent) {
		if(umlParent instanceof BehavioralFeature) {
			return ((BehavioralFeature)umlParent).getOwnedParameters().remove(element);
		}
		if(umlParent instanceof Behavior) {
			return ((Behavior)umlParent).getOwnedParameters().remove(element);
		}
		return false;
	}
	
	/* (non-Javadoc)
	 * @see com.cea.papyrus.core.common.factories.NodeFactory#getBaseString()
	 */
	@Override
	public String getBaseString() {
		return "param_"; //$NON-NLS-1$
	}	
}